//
//  MYGMeetingListDetailViewController.swift
//  MYDoctor
//
//  Created by 王振明 on 2024/5/13.
//

import UIKit

class MYGMeetingListDetailViewController: MYGBaseController {
    var mod:MYGMeetingRoomListModel!
    override func viewDidLoad() {
        super.viewDidLoad()
        configUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let barBtnItem:UIBarButtonItem = UIBarButtonItem(customView: backBtn)
        self.navigationItem.leftBarButtonItem = barBtnItem
    }
    private func configUI(){
        self.title = "查看会议"
        view.backgroundColor = .rgba(243, 243, 243)
        // 通过UIColor对象设置导航栏的背景颜色
        navigationController?.navigationBar.barTintColor = UIColor.clear
        navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
        view.addSubview(headImageV)
        headImageV.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(statusBarHeight + 44)
            make.top.equalToSuperview().offset(-statusBarHeight - 44)
        }
        view.addSubview(scheduleTable)
        scheduleTable.snp.makeConstraints { make in
            make.left.top.right.bottom.equalToSuperview()
        }
    }
    private lazy var scheduleTable: UITableView = {
        let cont = UITableView(frame: CGRectZero, style: .grouped)
        cont.delegate = self
        cont.dataSource = self
        cont.separatorStyle = .none
        cont.backgroundColor = .clear
        cont.register(cellWithClass: MYGMeetingListDetailTableViewCell.self)
        cont.allowsMultipleSelectionDuringEditing = true
        return cont
    }()
    private lazy var headImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "schedule_head")
        return cont
    }()    //MARK: lazy
    lazy var backBtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "Chat/back"), for: .normal)
        control.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        return control
    }()
}
extension MYGMeetingListDetailViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 154.5
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let vi = UIView()
        vi.backgroundColor = .rgba(0, 59, 223, 0.06)
        let nameLabel = UILabel()
        nameLabel.textColor = .rgba(0, 59, 223, 1)
        nameLabel.font = .medium(18)
        nameLabel.text = mod.sessionCn
        vi.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.top.equalToSuperview().offset(16)
            make.height.equalTo(25)
        }
        
        let timeLabel = UILabel()
        timeLabel.textColor = .rgba(0, 59, 223, 1)
        timeLabel.font = .medium(14)
        timeLabel.text = "时间: \(mod.roomStartTime) - \(mod.roomEndTime)"
        vi.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.top.equalTo(nameLabel.snp.bottom).offset(2.5)
            make.height.equalTo(20)
        }
        
        let huichangLabel = UILabel()
        huichangLabel.textColor = .rgba(0, 59, 223, 1)
        huichangLabel.font = .medium(14)
        huichangLabel.text = "会场: \(mod.roomCn)"
        vi.addSubview(huichangLabel)
        huichangLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.top.equalTo(timeLabel.snp.bottom).offset(2.5)
            make.height.equalTo(20)
        }
        
        let lineV = UIView()
        lineV.backgroundColor = .rgba(220, 220, 220, 1)
        vi.addSubview(lineV)
        lineV.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
            make.top.equalTo(huichangLabel.snp.bottom).offset(16.5)
        }
        
        let arr = ["时间","讲题","任务","姓名"]
        for ind in 0...3 {
            let lab = UILabel()
            lab.textColor = .rgba(77, 124, 254, 1)
            lab.font = .regular(13)
            lab.text = arr[ind]
            lab.textAlignment = .center
            vi.addSubview(lab)
            lab.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(Float(screenWidth/4)*Float(ind))
                make.bottom.equalToSuperview()
                make.height.equalTo(50)
                make.width.equalTo(screenWidth/4)
            }
        }
        return vi
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return mod.speechList.count
    }
//    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        return 194
//    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withClass: MYGMeetingListDetailTableViewCell.self, for: indexPath)
        cell.selectionStyle = .none
        cell.model = mod.speechList[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let unbind = UIContextualAction(style: .normal, title: "删除") {[weak self]
            (action, view, completionHandler) in
            guard let `self` = self else {return}
            
            completionHandler(true)
        }
        unbind.backgroundColor = UIColor.init(hexString: "#FF0000")
        
        let configuration = UISwipeActionsConfiguration(actions: [unbind])
        return configuration
    }
}
